/**
 * @author 刘新
 */
var ws = new WebSocket("ws://127.0.0.1:8000");
//连接打开时触发
ws.onopen = function(evt) {
    console.log("Connection open ...");
    ws.send("Hello WebSockets!");
};
//接收到消息时触发
ws.onmessage = function(evt) {
    console.log("Received Message: " + evt.data);
};
//连接关闭时触发
ws.onclose = function(evt) {
    console.log("Connection closed.");
};
$("#sendmsg").bind("click",function(){
    ws.send($("#sendtext").val());
    var html="<div class='send'><div class='msg'><img src='' />"+
        "<p><i class='msg_input'></i>"+$("#sendtext").val()+"</p></div></div>";
    upView(html);
})
function send(){

    var html="<div class='send'><div class='msg'><img src="+headSrc+" />"+
        "<p><i class='msg_input'></i>"+str+"</p></div></div>";
    upView(html);
}

function show(headSrc,str){
    var html="<div class='show'><div class='msg'><img src="+headSrc+" />"+
        "<p><i class='msg_input'></i>"+str+"</p></div></div>";
    upView(html);
}

function upView(html){
    $('.message').append(html);
    $('body').animate({scrollTop:$('.message').outerHeight()-window.innerHeight},200)
}
function sj(){
    return parseInt(Math.random()*10)
}
$(function(){
    $('.footer').on('keyup','input',function(){
        if($(this).val().length>0){
            $(this).next().css('background','#114F8E').prop('disabled',true);

        }else{
            $(this).next().css('background','#ddd').prop('disabled',false);
        }
    })
    $('.footer p').click(function(){
        show("./images/touxiangm.png",$(this).prev().val());
    })
})


